package compare

import (
	"awesomeProject2/elm"
	"awesomeProject2/mt"
	"awesomeProject2/write_line"
	"fmt"
	"strconv"
	"strings"
)

func Compare() {
	//nameselm := product.OpenNameLine("C:\\Users\\admin\\GolandProjects\\waimaigo\\elm\\产品.txt")
	//namesmt := product.OpenNameLine("C:\\Users\\admin\\GolandProjects\\waimaigo\\mt\\产品.txt")

	mtsMt := mt.GetFileMt()
	mtsElm := elm.GetFileElm()

	sfc := make([]string, 0)
	ecode := make([]string, 0)
	names := make([]string, 0)
	activityPrices := make([]string, 0)
	prices := make([]string, 0)
	monthSale := make([]string, 0)
	category1 := make([]string, 0)
	category2 := make([]string, 0)
	cplines := make([]string, 0)
	pngs := make([]string, 0)

	for _, products := range mtsElm {
		for _, datum := range products.Data.Data {
			for _, productMt := range mtsMt {
				for _, datumMt := range productMt.Data.ProductList {

					//mtTitle := name.GetNameByTitle(datumMt.Name)
					//elmTitle := name.GetNameByTitle(datum.Title)
					if datumMt.Name == datum.Title {
						println(datum.Title)
						if strings.Contains(datum.Title, "唯爱") {
							fmt.Println(datum.Title)
						}
						codemt := datumMt.WmProductSkus[0].SourceFoodCode
						println(codemt)
						sfc = append(sfc, ""+codemt)
						ecode = append(ecode, datum.BarCode)
						names = append(names, datum.Title)
						pngs = append(pngs, datum.PicURL)
						if datum.CustomCategoryParentName == "" {
							category1 = append(category1, datum.CustomCategoryName)
							category2 = append(category2, "")
						} else {
							category1 = append(category1, datum.CustomCategoryParentName)
							category2 = append(category2, datum.CustomCategoryName)
						}

						//download.Download(datum.PicURL, name.GetNameByTitle(datumMt.Name))

						//教师节礼物【木槿】11朵红玫瑰花小香风花束花店配送鲜花玫瑰花送花上门花店鲜花鲜花外卖	98	39.9	3081	14799842766

						if datumMt.SellCount > datum.MonthlySaledQuantity {
							monthSale = append(monthSale, strconv.Itoa(datumMt.SellCount))
						} else {
							monthSale = append(monthSale, strconv.Itoa(datum.MonthlySaledQuantity))
						}
						price := strconv.FormatFloat(datum.Price, 'f', 2, 64)
						prices = append(prices, price)
						if datum.MinActivePrice == 0 {
							activityPrices = append(activityPrices, strconv.FormatFloat(datum.Price, 'f', 2, 64))
						} else {
							activityPrices = append(activityPrices, strconv.FormatFloat(datum.MinActivePrice, 'f', 2, 64))
						}
						sprintf := fmt.Sprintf("%s#%s#%s#%s#%s#%s", monthSale[len(monthSale)-1], datum.Title, price, activityPrices[len(activityPrices)-1], codemt, datum.BarCode)
						cplines = append(cplines, sprintf)
					}
					//for _, tag := range datumMt.TagList {
					//
					//	if strings.Contains(tag.Name, "店长推荐") {
					//
					//	}
					//}
				}
			}
		}
	}

	write_line.WriteLineTxm(names, "C:\\Users\\admin\\GolandProjects\\waimaigo\\mt\\activity.txt")
	write_line.WriteLineTxm(sfc, "C:\\Users\\admin\\GolandProjects\\waimaigo\\mt\\activity_code.txt")
	write_line.WriteLineTxm(ecode, "C:\\Users\\admin\\GolandProjects\\waimaigo\\mt\\ecode.txt")
	write_line.WriteLineTxm(activityPrices, "C:\\Users\\admin\\GolandProjects\\waimaigo\\mt\\activity_price.txt")
	write_line.WriteLineTxm(prices, "C:\\Users\\admin\\GolandProjects\\waimaigo\\mt\\prices.txt")
	write_line.WriteLineTxm(monthSale, "C:\\Users\\admin\\GolandProjects\\waimaigo\\mt\\monthSale.txt")
	write_line.WriteLineTxm(category1, "C:\\Users\\admin\\GolandProjects\\waimaigo\\mt\\category1.txt")
	write_line.WriteLineTxm(category2, "C:\\Users\\admin\\GolandProjects\\waimaigo\\mt\\category2.txt")
	write_line.WriteLineTxm(cplines, "C:\\Users\\admin\\GolandProjects\\waimaigo\\mt\\cp_lines.txt")
	write_line.WriteLineTxm(pngs, "C:\\Users\\admin\\GolandProjects\\waimaigo\\mt\\png.txt")

}
